#
#        Python GUI - Actions - Generic
#

from Properties import overridable_property
from JHacks import * ##*change*

class Action(object):
    """Action is a mixin class providing the ability for an
    object to invoke a user-specified action."""
    
    action = overridable_property('action', """Action to be performed.
        May be <action> or (<action>, <arg>...) where <action> is either
        a message name or a callable object.""")

    _action = None
    _action_args = ()

    def get_action(self):
        return (self._action,) + self._action_args

    def set_action(self, x):
        if isinstance(x, tuple):
            action = x[0]
            args = x[1:]
        else:
            action = x
            args = ()
        self._action = action
        self._action_args = args

    def do_action(self):
        "Invoke the action."
        action = self._action
        if action:
            args = self._action_args
            if isinstance(action, str):
                self.handle(action, *args)
            else:
                action(*args)
